import useUserStore from "@/store/modules/user";

export default {
  mounted(el, binding) {
    const { value } = binding;
    const allPermission = "*:*:*";
    const userPermissions = useUserStore().permissions;
    if (!Array.isArray(value) || !value?.length) {
      console.error("指令缺少权限标签值，请传入一个非空数组");
      return;
    }
    const hasPermission = userPermissions.some(permission => permission === allPermission || value.includes(permission));
    !hasPermission && el.parentNode?.removeChild(el);
  }
};
